CC = gcc
CFLAGS = -Wall -g -Iinclude
LDFLAGS = -lmpg123 -lao -lpthread

# Source and object files
SRC_DIR = src
OBJ_DIR = .
OBJS = $(OBJ_DIR)/gps.o $(OBJ_DIR)/gps_navigator.o $(OBJ_DIR)/display_console.o $(OBJ_DIR)/vehicle_sensors.o $(OBJ_DIR)/media_controller.o $(OBJ_DIR)/data_bus.o
SRCS = $(SRC_DIR)/gps.c $(SRC_DIR)/gps_navigator.c $(SRC_DIR)/display_console.c $(SRC_DIR)/vehicle_sensors.c $(SRC_DIR)/media_controller.c $(SRC_DIR)/data_bus.c

# Default target
all: infotainment

# Link objects into executable
infotainment: $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

# Compile source files to objects
$(OBJ_DIR)/gps.o: $(SRC_DIR)/gps.c include/gps.h
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/gps_navigator.o: $(SRC_DIR)/gps_navigator.c include/gps_utils.h include/gps.h
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/display_console.o: $(SRC_DIR)/display_console.c include/gps_utils.h include/media_defs.h
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/vehicle_sensors.o: $(SRC_DIR)/vehicle_sensors.c include/gps_utils.h
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/media_controller.o: $(SRC_DIR)/media_controller.c include/media_defs.h
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/data_bus.o: $(SRC_DIR)/data_bus.c include/gps_utils.h include/media_defs.h
	$(CC) $(CFLAGS) -c $< -o $@

# Clean up
clean:
	rm -f $(OBJS) infotainment